/*
 * bufferwrite.hpp
 *
 *  Created on: 2016年4月8日
 *      Author: win7
 */


	write_return write(const char* buf, int32_t length){
		return write((const unsigned char*)(buf), length);
	}
	write_return write(const buffer_impl& buffer){
		return write(buffer.get_read_buffer(), buffer.length());
	}
	write_return write(const buffer_impl& buffer, int32_t length){
		return write(buffer.get_read_buffer(), length);
	}
	write_return write(unsigned char value){
		return write(static_cast<unsigned char*>(&value), sizeof(value));
	}
	write_return write(unsigned short value){
		value = ::htons(value);
		return write((unsigned char*)(&value), sizeof(value));
	}
	write_return write(unsigned int value){
		switch(sizeof(value)){
		case 2:
			value = ::htons(static_cast<uint16_t>(value));
			return write((const unsigned char*)(&value), sizeof(value));
		case 4:
			value = ::htonl(static_cast<uint32_t>(value));
			return write((const unsigned char*)(&value), sizeof(value));
		case 8:
			return write(static_cast<unsigned long long>(value));
		default:
			return default_write_return;
		}
	}
	write_return write(unsigned long value){
		switch(sizeof(value)){
		case 4:
			value = ::htonl(static_cast<uint32_t>(value));
			return write((const unsigned char*)(&value), sizeof(value));
		case 8:
			return write(static_cast<unsigned long long>(value));
		default:
			return default_write_return;
		}
	}
	write_return write(unsigned long long value){
//		uint32_t low = ::htonl(static_cast<uint32_t>(value&0xFFFFFFFF));
//		uint32_t high = ::htonl(static_cast<uint32_t>((value >> 32)&0xFFFFFFFF));
//		value = (static_cast<uint64_t>(low) << 32) | high;
		value = (static_cast<uint64_t>(::htonl(static_cast<uint32_t>(value&0xFFFFFFFF))) << 32) | ::htonl(static_cast<uint32_t>((value >> 32)&0xFFFFFFFF));
		return write((const unsigned char*)(&value), sizeof(value));
	}

	write_return write(signed char value){
		return write((const unsigned char*)(&value), sizeof(value));
	}
	write_return write(signed short value){
		return write(static_cast<unsigned short>(value));
	}
	write_return write(signed int value){
		return write(static_cast<unsigned int>(value));
	}
	write_return write(signed long value){
		return write(static_cast<unsigned long>(value));
	}
	write_return write(signed long long value){
		return write(static_cast<unsigned long long>(value));
	}

